/*
 *  This file is part of Bracket Security
 *  Copyright 2011 David R. Smith
 *
 */
package asia.redact.bracket.security;

import javax.crypto.spec.SecretKeySpec;

/**
 * Wrapper to pass in our arguments in raw String form. Strings are assumed to have
 * been encoded as UTF-8.
 * 
 * @author Dave
 *  @see SecurityTool
 */
public class EncryptParams {
	
	public final String alias;
	public final String message;
	public final String symmetricAlgorithm;
	// optional, if not present key will be generated within the Tool
	public SecretKeySpec symmetricKey;
	
	public EncryptParams(String alias, String message, String symmetricAlgorithm) {
		super();
		this.alias = alias;
		this.message = message;
		this.symmetricAlgorithm = symmetricAlgorithm;
	}

	public boolean hasKey(){
		return symmetricKey != null;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((alias == null) ? 0 : alias.hashCode());
		result = prime * result + ((message == null) ? 0 : message.hashCode());
		result = prime
				* result
				+ ((symmetricAlgorithm == null) ? 0 : symmetricAlgorithm
						.hashCode());
		result = prime * result
				+ ((symmetricKey == null) ? 0 : symmetricKey.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof EncryptParams)) {
			return false;
		}
		EncryptParams other = (EncryptParams) obj;
		if (alias == null) {
			if (other.alias != null) {
				return false;
			}
		} else if (!alias.equals(other.alias)) {
			return false;
		}
		if (message == null) {
			if (other.message != null) {
				return false;
			}
		} else if (!message.equals(other.message)) {
			return false;
		}
		if (symmetricAlgorithm == null) {
			if (other.symmetricAlgorithm != null) {
				return false;
			}
		} else if (!symmetricAlgorithm.equals(other.symmetricAlgorithm)) {
			return false;
		}
		if (symmetricKey == null) {
			if (other.symmetricKey != null) {
				return false;
			}
		} else if (!symmetricKey.equals(other.symmetricKey)) {
			return false;
		}
		return true;
	}
	
}
